﻿namespace SuperX.Helper
{
    public class Error
    {
        public Error()
        {
        }

        public Error(string message, int code)
        {
            Message = message;
            Code = code;
        }

        public string Message { get; set; }

        public Error InnerError { get; set; }

        public int Code { get; set; }

        public override string ToString()
        {
            return Message;
        }

        public string GetLastErrorMsg()
        {
            if (InnerError != null)
            {
                return InnerError.GetLastErrorMsg();
            }
            else
            {
                return Message;
            }
        }

        public bool SearchError(string filterStr, bool includeInnerError = true)
        {
            if (Message != null && Message.ToUpper().Contains(filterStr.ToUpper()))
            {
                return true;
            }
            else
            {
                if (includeInnerError == false || InnerError == null)
                {
                    return false;
                }
                else
                {
                    return InnerError.SearchError(filterStr, includeInnerError);
                }
            }
        }
    }
}